#include<iostream>
#include<map>
#include<string>
using namespace std;
string s;
map<string,int> huoxing_diqiu;
string a[13] = {"tret", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"};
string b[13] = {"####", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"};
void func1(int i){
	if(i/13) cout<<b[i/13];
	if(i/13&&i%13) cout<<" ";
	if(i%13||i==0) cout<<a[i%13]<<endl;
	else{cout<<endl;}
}

void func2(){
	int len=s.length();
	string s1=s.substr(0,3);
	int t1=0,t2=0;
	string s2;
	if(len>4) s2=s.substr(4,3);
	
	for(int i=0;i<13;i++){
		if(s1==b[i]) t1=i;
		if(s2==a[i]||s1==a[i]) t2=i;
	}
	cout<<t1*13+t2<<endl;
	
}

int main(){
	freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	getchar();
	while(n--){
		
		getline(cin,s);
		if(s[0]>='a'&&s[0]<='z'){
			func2();
		}else{
			func1(stoi(s));

		}

	}
}